package com.ruoyi.web.util;

import java.util.ArrayList;
import java.util.List;

import javax.xml.xpath.XPathConstants;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import com.ruoyi.supervise.domain.RelatedDesignUnits;
import com.ruoyi.supervise.domain.WDCertificateTextUnit;

import cn.hutool.core.util.XmlUtil;

public class XmlReadUtil {

	/**
	 * @Title: getRelatedDesignUnitsXml
	 * @Description: 图审设计单位信息
	 * @Author wtj
	 * @DateTime 2020年3月20日 下午3:53:47
	 * @param strXml
	 * @param nodePath
	 * @param rdu
	 * @return
	 */
	public static List<RelatedDesignUnits> getRelatedDesignUnitsXml(String strXml, String nodePath, RelatedDesignUnits rdu){
		Document docResult=XmlUtil.readXML(strXml);
		NodeList nodeList = XmlUtil.getNodeListByXPath(nodePath, docResult);
		List<RelatedDesignUnits> rduList = new ArrayList<RelatedDesignUnits>();
		for (int i = 1; i < nodeList.getLength()+1; i++) {
			RelatedDesignUnits rduNew=new RelatedDesignUnits();
			Object guid =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getGuid(), docResult, XPathConstants.STRING);
			rduNew.setGuid(String.valueOf(guid));
			Object name =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getName(), docResult, XPathConstants.STRING);
			rduNew.setName(String.valueOf(name));
			Object linkMan =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getLinkMan(), docResult, XPathConstants.STRING);
			rduNew.setLinkMan(String.valueOf(linkMan));
			Object linkTel =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getLinkTel(), docResult, XPathConstants.STRING);
			rduNew.setLinkTel(String.valueOf(linkTel));
			Object linkEMail =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getLinkEMail(), docResult, XPathConstants.STRING);
			rduNew.setLinkEMail(String.valueOf(linkEMail));
			Object designContractAmount =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getDesignContractAmount(), docResult, XPathConstants.STRING);
			rduNew.setDesignContractAmount(String.valueOf(designContractAmount));
			Object leadMan =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getLeadMan(), docResult, XPathConstants.STRING);
			rduNew.setLeadMan(String.valueOf(leadMan));
			Object certLevel =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getCertLevel(), docResult, XPathConstants.STRING);
			rduNew.setCertLevel(String.valueOf(certLevel));
			Object certNum =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getCertNum(), docResult, XPathConstants.STRING);
			rduNew.setCertNum(String.valueOf(certNum));
			Object performs =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getPerforms(), docResult, XPathConstants.STRING);
			rduNew.setPerforms(String.valueOf(performs));
			Object performsIDCard =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getPerformsIDCard(), docResult, XPathConstants.STRING);
			rduNew.setPerformsIDCard(String.valueOf(performsIDCard));
			Object projectDir =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getProjectDir(), docResult, XPathConstants.STRING);
			rduNew.setProjectDir(String.valueOf(projectDir));
			Object projectDirIDCard =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getProjectDirIDCard(), docResult, XPathConstants.STRING);
			rduNew.setProjectDirIDCard(String.valueOf(projectDirIDCard));
			Object dean =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getDean(), docResult, XPathConstants.STRING);
			rduNew.setDean(String.valueOf(dean));
			Object deanIDCard =XmlUtil.getByXPath(nodePath +"["+i+"]/" + rdu.getDeanIDCard(), docResult, XPathConstants.STRING);
			rduNew.setDeanIDCard(String.valueOf(deanIDCard));
			rduList.add(rduNew);
		}
		return rduList;
	}
	
	/**
	 * @Title: getCertificateTextXml
	 * @Description: 获取合格证信息
	 * @Author wtj
	 * @DateTime 2020年3月27日 下午3:03:38
	 * @param strXml
	 * @param nodePath
	 * @param ct
	 * @return
	 */
	public static List<WDCertificateTextUnit> getCertificateTextXml(String strXml, String nodePath, WDCertificateTextUnit ctu){
		Document docResult=XmlUtil.readXML(strXml);
		NodeList nodeList = XmlUtil.getNodeListByXPath(nodePath, docResult);
		List<WDCertificateTextUnit> ctuList = new ArrayList<WDCertificateTextUnit>();
		for (int i = 1; i < nodeList.getLength()+1; i++) {
			WDCertificateTextUnit ctuNew=new WDCertificateTextUnit();
			Object guid =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getGuid(), docResult, XPathConstants.STRING);
			ctuNew.setGuid(String.valueOf(guid));
			Object name =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getName(), docResult, XPathConstants.STRING);
			ctuNew.setName(String.valueOf(name));
			Object layer =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getLayer(), docResult, XPathConstants.STRING);
			ctuNew.setLayer(String.valueOf(layer));
			Object upArea =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getUpArea(), docResult, XPathConstants.STRING);
			ctuNew.setUpArea(String.valueOf(upArea));
			Object downArea =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getDownArea(), docResult, XPathConstants.STRING);
			ctuNew.setDownArea(String.valueOf(downArea));
			Object applicationArea =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getApplicationArea(), docResult, XPathConstants.STRING);
			ctuNew.setApplicationArea(String.valueOf(applicationArea));
			Object collectHotArea =XmlUtil.getByXPath(nodePath +"["+i+"]/" + ctu.getCollectHotArea(), docResult, XPathConstants.STRING);
			ctuNew.setCollectHotArea(String.valueOf(collectHotArea));
			ctuList.add(ctuNew);
		}
		return ctuList;
	}
}
